package com.atguigu.easyexcel;

import com.alibaba.excel.EasyExcel;
import com.atguigu.easyexcel.dto.ExcelStudentDTO;
import com.atguigu.easyexcel.listener.ExcelStudentDTOListener;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @program: srb
 * @author: 龙龙
 * @create: 2022-01-23 16:32
 * @description:
 **/
public class ExcelWriteTest {
    @Test
    public void write(){
        //使用easyExcel向硬盘输出一个excel文本
        //java对象的属性->excel的列

        ArrayList<ExcelStudentDTO> excelStudentDTOS = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            ExcelStudentDTO studentDTO = new ExcelStudentDTO();
            studentDTO.setBirthday(new Date());
            studentDTO.setSalary(i*1000d);
            studentDTO.setName("小学生小"+i);
            excelStudentDTOS.add(studentDTO);
        }
        String path = "h:/simpleWrite.xlsx";
        EasyExcel.write(path,ExcelStudentDTO.class)
        .sheet("小学生信息").doWrite(excelStudentDTOS);

    }

    @Test
    public void read(){
        String path = "h:/simpleWrite.xlsx";
        EasyExcel.read(path,ExcelStudentDTO.class,new ExcelStudentDTOListener())
                .sheet().doRead();
    }
}
